package net.tngou.action;

import java.io.IOException;
import java.sql.Date;
import java.sql.Timestamp;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

import javax.servlet.ServletException;

import net.tngou.pojo.Item;
import net.tngou.pojo.Result;
import net.tngou.util.DateUtil;
import net.tngou.util.DigestMD;


public class ItemAction extends BaseAction {

	@Override
	public void execute() throws ServletException, IOException {
		
		Item item =(Item) session.getAttribute("item_"+ask.getId());
		 if(item==null)
		 {
			 item = new Item().get(ask.getId());
			 session.setAttribute("item_"+ask.getId(), item);

		 }
		
		 if(item==null)
		 {
			run_404();
			return;
		 }
		
		 Timestamp st = item.getStart_time();
		 Timestamp et = item.getStop_time();
		 root.put("stop", -1);
		 if(item.getIs_stop()==1)
		 {
			 java.util.Date now = new java.util.Date();
			 
			 if((now.getTime()-st.getTime())>0)
			 {

				 if(now.getTime()-et.getTime()<0)
				 {
					 root.put("stop", item.getIs_stop());
					 String ism = _GetCookieIsm(0);
					 if(ism==null)
					 {
						 UUID uuid = UUID.randomUUID();  
						 ism="tg-0-"+uuid.toString()+"-"+DigestMD.MD2(1+"")+"-0";
						 response.addMCookie(0,ism);						 
					 }
					 session.setAttribute(ism, "0");
				 }else {
					 root.put("stop", -1);
				 }
 
			 }else
			 {
				 root.put("stop", 0);
			 }
			 
		 }
		
		 root.put("item", item);
		 root.put("title", item.getTheme()+"第五届最美“十大金牛好人” 评选活动"+ item.getOption());    
		 root.put("keywords", "最美“十大金牛好人” ");
		 root.put("description", item.getTheme()+"第五届最美“十大金牛好人” 评选活动"+ item.getOption());
		 printFreemarker("default/item.ftl", root);
		 
		 
		 
	}
	
	 
}
